package hanjia;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/15-下午4:13
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode46 {

    public  List<List<Integer>> permute(int[] nums) {
        Boolean[] visited = new Boolean[nums.length];
        Arrays.fill(visited,false);
        List<Integer> result = new ArrayList<>();
        List<List<Integer>> results = new ArrayList<>();
        backtracking(visited, result, results, nums);
        return results;



    }

    private void backtracking(Boolean[] visited, List<Integer> result, List<List<Integer>> results, int[] nums) {

        if (result.size()==visited.length){

            results.add(new ArrayList<>(result));
            return;
        }



     for (int i=0;i<visited.length;i++){
         if (visited[i]){
             continue;
         }
         visited[i]=true;
         result.add(nums[i]);
         backtracking(visited,result,results,nums);
         result.remove(result.size()-1);
         visited[i]=false;



     }

    }
}
